home *** CD-ROM | disk | FTP | other *** search
- PROGRAM DesignerButtons;
- {Program name:DesignerButtons.Pas }
- {Function: This is the main module for this program. }
- {History: 12/19/88 Original by Prototyper. }
- { Modified 1/6/89 }
- USES
- AboutDialog, ExampleWindow, InitTheMenus, HandleTheMenus;
- VAR {Main variables}
- myEvent : EventRecord; {Event record for all events}
- doneFlag : boolean; {Exit program flag}
- code : integer; {Determine event type}
- whichWindow, theMainWindow : WindowPtr; {See which window for event}
- mResult : longint; {Menu list and item selected values}
- theMenu, theItem : integer; {Menu list and item selected}
- chCode : integer; {Key code}
- ch : char; {Key pressed in Ascii}
-
- BEGIN {Start of main body}
-
- MoreMasters; {This reserves space for more handles}
- InitGraf(@thePort); {Quickdraw Init}
- InitFonts; {Font manager init}
- InitWindows; {Window manager init}
- InitMenus; {Menu manager init}
- TEInit; {Text edit init}
- InitDialogs(NIL); {Dialog manager}
-
- FlushEvents(everyEvent, 0); {Clear out all events}
- InitCursor; {Make an arrow cursor}
-
- doneFlag := FALSE; {Do not exit program yet}
-
- Init_My_Menus; {Initialize menu bar}
-
- Init_ExampleWindow; {Initialize the window routines}
- Open_ExampleWindow(theMainWindow); {Open the window routines at program start}
-
- REPEAT {Start of main event loop}
- SystemTask; {For support of desk accessories}
-
- IF GetNextEvent(everyEvent, myEvent) THEN {If event then...}
- BEGIN {Start handling the event}
- code := FindWindow(myEvent.where, whichWindow); {Get which window the event happened in}
-
- CASE myEvent.what OF {Decide type of event}
-
- MouseDown : {Mouse button pressed}
- BEGIN {Handle the pressed button}
- IF (code = inMenuBar) THEN {See if a menu selection}
- BEGIN {Get the menu selection and handle it}
- mResult := MenuSelect(myEvent.Where); {Do menu selection}
- theMenu := HiWord(mResult); {Get the menu list number}
- theItem := LoWord(mResult); {Get the menu list item number}
- Handle_My_Menu(doneFlag, theMenu, theItem); {Handle the menu}
- END; {End of inMenuBar}
-
- IF (code = inContent) THEN {See if in a window}
- BEGIN {Handle the hit inside a window}
- IF (whichWindow <> FrontWindow) THEN {See if already selected or not, in front if selected}
- SelectWindow(whichWindow) {Select this window to make it active}
- ELSE {If already in front the already selected}
- BEGIN {Handle the button in the content}
- SetPort(whichWindow); {Get ready to draw in this window}
- Do_ExampleWindow(myEvent); {Handle this window}
- END; {End of else}
- END; {End of inContent}
-
- IF (code = inSysWindow) THEN {See if a DA selection}
- SystemClick(myEvent, whichWindow); {Let other programs in}
-
- END; {End of MouseDown}
-
- KeyDown, AutoKey : {Handle key inputs}
- BEGIN {Get the key and handle it}
- WITH myevent DO {Check for menu command keys}
- BEGIN {}
- chCode := BitAnd(message, CharCodeMask); {Get character}
- ch := CHR(chCode); {Change to ASCII}
- IF (Odd(modifiers DIV CmdKey)) THEN {See if Command key is down}
- BEGIN {}
- mResult := MenuKey(ch); {See if menu selection}
- theMenu := HiWord(mResult); {Get the menu list number}
- theItem := LoWord(mResult); {Get the menu item number}
- IF (theMenu <> 0) THEN {See if a list was selected}
- Handle_My_Menu(doneFlag, theMenu, theItem); {Do the menu selection}
- END; {}
- END; {End for with}
- END; {End for KeyDown,AutoKey}
-
- UpDateEvt : {Update event for a window}
- BEGIN {Handle the update}
- whichWindow := WindowPtr(myEvent.message); {Get the window the update is for}
- BeginUpdate(whichWindow); {Set the clipping to the update area}
- Update_ExampleWindow(whichWindow); {Update this window}
- EndUpdate(whichWindow); {Return to normal clipping area}
- END; {End of UpDateEvt}
-
- ActivateEvt : {Window activated event}
- BEGIN {Handle the activation}
- whichWindow := WindowPtr(myevent.message); {Get the window to be activated}
- IF odd(myEvent.modifiers) THEN {Make sure it is Activate and not DeActivate}
- SelectWindow(whichWindow); {Activate the window by selecting it}
- END; {End of ActivateEvt}
-
- OTHERWISE {Used for debugging, to see what other events are coming in}
- ; {End of otherwise}
-
- END; {End of case}
-
- END; {end of GetNextEvent}
- UNTIL doneFlag; {End of the event loop}
-
- DisposeWindow(theMainWindow); {Will bomb if you don't dispose of it}
-
- END. {End of the program}